package kr.hkit.androidcomplete01.ch07;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class OffScreen extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyView(this));
	}

	class MyView extends View {

		private Paint paint;
		private Canvas offscreen;
		private Bitmap back;

		public MyView(Context context) {
			super(context);
			paint = new Paint(Paint.ANTI_ALIAS_FLAG);
			back = Bitmap
					.createBitmap(460, 200, Bitmap.Config.ARGB_8888);
			offscreen = new Canvas(back);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			canvas.drawColor(Color.LTGRAY);
			offscreen.drawColor(Color.GREEN);
			paint.setColor(Color.RED);
			for (int x = 0; x < 460; x += 10) {
				offscreen.drawLine(x, 0, 460 - x, 200, paint);
			}

			canvas.drawBitmap(back, 10, 10, null);
		}
	}
}
